<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BAuthItem
 *
 * @author jianfeng
 */
class BAuthItem {
    
    const RoleType_Mixed = "mixed";

    //put your code here
    private $id = null;
    private $name = null;
    private $app = null;
    private $type = null;
    private $showName = null;
    private $appId = null;

    public function __construct($id = null) {
        if ($id != null)
            $this->load($id);
    }

    public function load($id = null) {
        if ($id != null) {
            $this->id = $id;
            $mRole = BMApplicationAuthItem::model()->findByPk($id);
            $this->name = $mRole->authname;
            $this->showName = $mRole->showname;
            $this->appId = $mRole->app_id;
            $this->type = BMAuthItemType::model()->findByPk($mRole->authtype)->typename;
        }
    }

    public function getId() {
        return $this->id;
    }

    public function getName() {
        return $this->name;
    }

    public function getShowName() {
        return $this->showName;
    }

    public function getAuthType() {
        return $this->type;
    }

    public function getServiceApp() {
        if ($this->app == NULL)
            $this->app = BServiceApp::getInstanceById($this->appId);
        return $this->app;
    }

    public function isAdminType() {
        $type = $this->getAuthType();

        if ($type == BBasicRolesTemplate::SERVEDTEAM_ADMIN_ROLE ||
                $type == BBasicRolesTemplate::SERVICE_ADMIN_ROLE ||
                $type == BBasicRolesTemplate::WORKTEAM_ADMIN_ROLE)
            return TRUE;

        return FALSE;
    }

    public function isMemberType() {
        $type = $this->getAuthType();

        if ($type == BBasicRolesTemplate::SERVEDTEAM_MEMBER_ROLE ||
                $type == BBasicRolesTemplate::SERVICE_MEMBER_ROLE ||
                $type == BBasicRolesTemplate::WORKTEAM_MEMBER_ROLE)
            return TRUE;

        return FALSE;
    }

}

?>
